<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
            <title>
            </title>
            <link href="__LAYUI__/css/layui.css" rel="stylesheet" type="text/css"/>
            <script src="__LAYUI__/layui.js" type="text/javascript">
            </script>
            <script src="__STATIC__/js/form.js" type="text/javascript">
            </script>
        </meta>
    </head>
    <body>
        <form class="layui-form" name="ArticleForm" style="margin: 20px 50px;">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    文章标题
                </label>
                <div class="layui-input-inline">
                    <input class="layui-input" lay-verify="required" name="title" type="text">
                    </input>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    文章分类
                </label>
                <div class="layui-input-inline">
                    <select name="category_id">
                        {volist name="categorys" id="v"}
                        <option value="{$v.id}" >{$v.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    点击数
                </label>
                <div class="layui-input-inline">
                    <input class="layui-input" lay-verify="required" name="click" type="text">
                    </input>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    状态
                </label>
                <div class="layui-input-block">
                    <input checked="" name="status" title="显示" type="radio" value="1"></input>
                    <input name="status" title="隐藏" type="radio" value="0"></input>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    文章内容
                </label>
                <div class="layui-input-block">
                    <textarea id="content" style="display: none;" name="content"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                        <input name="id" style="display: none;" type="text">
                        <button class="layui-btn layui-btn-normal" lay-filter="article" lay-submit="">
                            提交
                        </button>
                    </input>
                </div>
            </div>
        </form>
        <script type="text/javascript">
            var formObj = new Form('ArticleForm');
                formObj.init({$article});

            layui.use(['form','layer','layedit'], function(){
                var $ = layui.jquery;
                var layer = layui.layer;
                var form = layui.form();
                var layedit = layui.layedit;
                layedit.set({
                    uploadImage: {
                        url: "{:url('admin/Upload/layedit')}"
                    }
                });
                var index = layedit.build('content'); //建立编辑器

                form.on('submit(article)', function(e){
                    e.field.content = layedit.getContent(index)
                    $.post("{:url('admin/Article/editArticle')}", e.field, function(res){
                        if(res.status == 1){
                          layer.msg(res.msg,{time:1000},function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            parent.location.reload();
                          });
                        }else{
                          layer.msg(res.msg);
                        }
                    },'json');
                    return false;
                });

            });
        </script>
    </body>
</html>
